package com.zhongwang.business.module.taskManage.service;

import com.zhongwang.business.module.system.log.LogService;
import com.zhongwang.business.module.taskManage.dao.TaskDao;
import com.zhongwang.business.module.taskManage.dao.UnassignedTaskDao;
import com.zhongwang.business.module.taskManage.model.TaskModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskService {
    @Autowired
    private TaskDao taskDao;
    @Autowired
    private LogService logService;
    /**
     * 执行添加任务
     * @param model
     * @return
     */
    public Integer insertTask(TaskModel model){
        return taskDao.insertTask(model);
    }

    /**
     * 修改任务
     * @param model
     * @return
     */
    public Integer updateTask(TaskModel model){
        logService.saveLog("商务任务下达-分配调整", "项目id："+model.getFkId());
        return taskDao.updateTask(model);
    }


    /**
     * 查询下达任务的项目信息
     * @param fkId
     * @return
     */
    public List<TaskModel> selTaskList(Integer fkId){
        return taskDao.selTaskList(fkId);
    }

    /**
     * 查询id
     * @param model
     * @return
     */
    public int selTaskId(TaskModel model){
        return taskDao.selTaskId(model);
    }

    /**
     * 是否在用
     * @param fkId
     * @return
     */
    public List<TaskModel> selTaskIsUse(Integer fkId){
        List<TaskModel> list=taskDao.selTaskIsUse(fkId);
        return list;
    }

    /**
     * 查询任务节点的数据
     * @param model
     * @return
     */
    public TaskModel selectTaskByFkId(TaskModel model){
        return taskDao.selectTaskByFkId(model);
    }

    /**
     * 根据项目id和任务kind 查询下达时候任务的指派人。
     * @param fkId
     * @param tkind
     * @return
     */
    public String getAppointByIdAndKind(Integer fkId,Integer tkind){
        try {
            TaskModel model = new TaskModel();
            model.setFkId(fkId);
            model.setTkind(tkind);
            return taskDao.selTaskAppoint(model).getAppoint();
        }catch (Exception e){
            return "";
        }
    }
}
